#ifndef DECODEVIDEOTHREAD_H
#define DECODEVIDEOTHREAD_H

#ifdef __cplusplus
#define __STDC_CONSTANT_MACROS
#define UINT64_C
extern "C"
{
#endif
#include "libavcodec/avcodec.h"
#include "libavfilter/avfilter.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libavutil/ffversion.h"
#include "libswresample/swresample.h"
#include "libswscale/swscale.h"
#include "libpostproc/postprocess.h"
#include <libavutil/imgutils.h>
#ifdef __cplusplus
}
#endif

#include <QThread>
#include <QImage>
#include <QObject>

class DecodeVideoThread : public QThread
{
     Q_OBJECT
public:
    explicit DecodeVideoThread();
     ~DecodeVideoThread();

    void stop_run();
    void set_url(QString url);
    int get_width();
    int get_height();
    int open_input_file();

protected:
    void run();

signals:
    //使用QWidget时
    void sig_send_image(QImage);

    //使用OpenGL时
    void sigFirst(uchar* p,int w,int h);
    void newFrame();

private:
    AVFormatContext *mFmtCtx       =NULL;
    const AVCodec   *mVideoCodec   =NULL;
    AVCodecContext  *mVideoCodecCtx=NULL;
    AVPacket        *mPkt          = NULL;
    AVFrame         *mYUVFrame     = NULL;
    AVFrame         *mRGBFrame     = NULL;

    struct SwsContext *mImgCtx=NULL;
    unsigned char *mOutBuffer=nullptr;

    QString mUrl;
    int mVideoStreamIndex =-1;
    int mNumBytes = -1;

    //使用OpenGL显示时
    bool mIsFirst = true;
    int mWidth,mHeight;

    bool mRunStat;
};

#endif // DECODEVIDEOTHREAD_H
